from pymysql import *


def main():
    # 创建Connection连接
    conn = connect(host='localhost', port=3306, database='19python', user='root', password='python', charset='utf8')
    # 获得Cursor对象
    cs = conn.cursor()
    # 执行insert语句，并返回受影响的行数：添加一条数据
    # 增加
    # count = cs.execute('insert into classes(name) values("python_3班")')
    # 打印受影响的行数
    # print(count)

    # 更新
    # count = cs.execute('update classes set name="python-3班" where name="python_3班"')
    # 删除
    count = cs.execute('delete from classes where id=1')

    # 提交之前的操作，如果之前已经之执行过多次的execute，那么就都进行提交
    conn.commit()

    # 关闭Cursor对象
    cs.close()
    # 关闭Connection对象
    conn.close()


if __name__ == '__main__':
    main()
